package com.karolak.stock.strategy;

import java.util.ArrayList;
import java.util.List;

import com.karolak.stock.indicator.EmaInd;
import com.karolak.stock.indicator.HighInd;
import com.karolak.stock.indicator.Indicator;
import com.karolak.stock.indicator.LowInd;
import com.karolak.stock.indicator.SumInd;
import com.karolak.stock.oscilator.DiffOsc;

public class EmaStrategy extends Strategy {

	@Override
	protected String defineConfig() {
		return "{signalThreshold:0.0001,votingThreshold:0.75}";
	}

	@Override
	protected List<Indicator> defineVoters() {

		String chBase = "base";
		String chDelta = "delta";
		String chDiff = "diff";

		List<Indicator> voters = new ArrayList<Indicator>();

		Indicator price = getDataManager().addSeries(new Indicator("Price", getDataManager()), chBase);
		Indicator emaf = null;
		for (int p : getConfig().getPeriods()) {

			Indicator ema = getDataManager().addSeries(new EmaInd(getDataManager(), p, price), chBase);
			if (emaf == null) {
				emaf = price;
			}

			DiffOsc diffEma = getDataManager().addSeries(new DiffOsc(getDataManager(), p, emaf, ema)/*
																									 * ,
																									 * chDelta
																									 */);
			voters.add(diffEma);
			emaf = ema;

			Indicator low = getDataManager().addSeries(new LowInd(getDataManager(), p, price), chBase);
			Indicator high = getDataManager().addSeries(new HighInd(getDataManager(), p, price), chBase);

			DiffOsc diffDown = getDataManager().addSeries(new DiffOsc(getDataManager(), p, price, high)/*
																										 * ,
																										 * chDiff
																										 */);
			DiffOsc diffUp = getDataManager().addSeries(new DiffOsc(getDataManager(), p, price, low)/*
																									 * ,
																									 * chDiff
																									 */);
			SumInd trend = getDataManager().addSeries(new SumInd(getDataManager(), diffDown, diffUp));
			Indicator ema2 = getDataManager().addSeries(new EmaInd(getDataManager(), p, trend)/*
																							 * ,
																							 * chDiff
																							 */);

			voters.add(trend);
			voters.add(ema2);
		}
		return voters;
	}
}
